package com.example.module_mine.mine.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.example.module_mine.R
import com.example.module_mine.databinding.LayoutToolsItemBinding
import com.example.module_mine.mine.model.TabItem

/**
 * @author yaotianxue
 * @description
 * @date 2025/2/5
 */
class ToolAdapter(private val mTabItems:List<TabItem>,private val mOnItemClick:(TabItem) -> Unit): RecyclerView.Adapter<ToolAdapter.ToolViewHolder>() {

    inner class ToolViewHolder(val binding:LayoutToolsItemBinding):RecyclerView.ViewHolder(binding.root){}

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ToolViewHolder {
        val binding =  DataBindingUtil.inflate<LayoutToolsItemBinding>(LayoutInflater.from(parent.context), R.layout.layout_tools_item,parent,false)
        return ToolViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return mTabItems.size
    }

    /**
     * 绑定数据
     */
    override fun onBindViewHolder(holder: ToolViewHolder, position: Int) {
        val binding = DataBindingUtil.getBinding<LayoutToolsItemBinding>(holder.itemView)
        binding?.apply {
            item = mTabItems[position]
            vRedPoint.visibility = if(mTabItems[position].hasNew) View.VISIBLE else View.GONE //红点
            lTab.setOnClickListener { //点击事件
                mOnItemClick.invoke(mTabItems[position])
            }
        }
    }
}